import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test {
    public static void main(String[] args) {
        Fram fram=new Fram();
    }

}


class Fram extends JFrame implements ActionListener {

    JButton div,add;
   JLabel label,label1;
    JTextField t1,t2,t3;

    public Fram(){

      setLayout(new FlowLayout());
      Font font=new Font("Times New Roman",Font.BOLD,20);
      setTitle("xxx计算器");
      div=new JButton("除");
      add=new JButton("加");
      div.addActionListener(this);
      add.addActionListener(this);

      label=new JLabel("  ",JLabel.CENTER);
      label1=new JLabel("  ",JLabel.CENTER);
      t1=new JTextField(10);
      t2=new JTextField(10);
      t3=new JTextField(10);
      label.setFont(font);
      label1.setFont(font);

      add(t1);
      add(label);
      add(t2);
      add(label1);
      add(t3);
      add(add);
      add(div);
      t3.setEditable(false);
      setVisible(true);
      setSize(400,120);
      this.setResizable(false);
      this.setLocationRelativeTo(null);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }








    @Override
    public void actionPerformed(ActionEvent e) {
        double n=0;
        try{
            if(e.getSource()==add){
                double n1,n2;
                n1=Double.parseDouble(t1.getText());
                n2=Double.parseDouble(t2.getText());
                n=n1+n2;
                t3.setText(String.valueOf(n));
                label.setText("+");
                label1.setText("=");




            }  else if (e.getSource()==div){
                double n1,n2;
                n1=Double.parseDouble(t1.getText());
                n2=Double.parseDouble(t2.getText());
                n=n1/n2;
                t3.setText(String.valueOf(n));
                label.setText("/");
                label1.setText("=");




            }

        }catch(NumberFormatException ee){
            t3.setText("请输入数字字符");
        }

    }
}
